<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="userForm" enctype="multipart/form-data">
                <br/>
                <h2 class="title">Relatório Cadastral</h2>
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <br/>
                <h4 class="title">Fator de Localização</h4>
                <p:panel id="fatorPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix">
                    <p:outputLabel value="Distrito:" styleClass="grid_3" for="dInput" />
                    <p:inputText id="dInput" styleClass="grid_4" 
                                 value="#{managerImovel.imovel.inscricaoCadastralD}" />

                    <p:outputLabel value="Setor:" styleClass="grid_3" for="sInput" />
                    <p:inputText id="sInput" styleClass="grid_4" 
                                 value="#{managerImovel.imovel.inscricaoCadastralS}" />

                    <p:outputLabel value="Quadra:" styleClass="grid_3" for="qInput" />
                    <p:inputText id="qInput" styleClass="grid_4" 
                                 value="#{managerImovel.imovel.inscricaoCadastralQuadra}" />
                    <div class="clear-both" />

                    <p:outputLabel value="Lote:" styleClass="grid_3" for="lInput" />
                    <p:inputText id="lInput" styleClass="grid_4" 
                                 value="#{managerImovel.imovel.inscricaoCadastralLote}" />

                    <p:outputLabel value="Unidade:" styleClass="grid_3" for="uInput" />
                    <p:inputText id="uInput" styleClass="grid_4" 
                                 value="#{managerImovel.imovel.inscricaoCadastralUnid}" />
                    <div class="clear-both" />
                </p:panel>


                <h4 class="title">Proprietário</h4>
                <p:panel id="ownerPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix">

                    <!--                                <p:outputLabel id="personOutputLabel" value="Pessoa:" 
                                                                   for="personRadioButton"
                                                                   styleClass="grid_3" style="top: 6px" />
                                                    <div class="grid_8">
                                                        <p:selectOneRadio id="personRadioButton" 
                                                                          value="  {managerSearchRealty.owner.typeDocument}" >
                                                            <f:selectItems value="{managerSearchRealty.typeDocumentList()}" />
                                                            <p:ajax event="change" update=":userForm:ownerPanel" />
                                                        </p:selectOneRadio>
                                                    </div>
                                                    <div class="clear-both" />
                                                    
                                                    <p:outputLabel value={managerSearchRealty.owner.typeDocument.type eq 'CPF' ? 'CPF:' : 'CNPJ:'}" 
                                                                   styleClass="grid_3" for="cpfInputMask" />
                                                    <p:inputMask id="cpfInputMask" styleClass="grid_4" 
                                                                 mask="{managerSearchRealty.owner.typeDocument.type eq 'CPF' 
                                                                         ? '999.999.999-99' : '99.999.999/9999-99'}"
                                                                 value="{managerSearchRealty.owner.typeDocument.type eq 'CPF' 
                                                                          ? managerSearchRealty.owner.cpf : managerSearchRealty.owner.cnpj}" />
                                                    <div class="clear-both" />-->

                    <!--                                <p:outputLabel value="Proprietário:" styleClass="grid_3" for="ownerAutoComplete" />
                                                    <p:autoComplete id="ownerAutoComplete" styleClass="grid_20" dropdown="true" converter="peopleconverter"
                                                                    var="item" itemLabel="{item.name} {item.cpf}" 
                                                                    itemValue="{item}" value="{managerSearchRealty.owner}" 
                                                                    scrollHeight="200" forceSelection="true"
                                                                    completeMethod="{managerSearchRealty.autocompletePeople}" />-->



                    <p:outputLabel value="Proprietário: "  styleClass="grid_3"/>
                    <p:selectOneRadio id="typePerson" 
                                      value="#{managerImovel.proprietario.tipoDocumento}" >  
                        <f:selectItems value="#{managerImovel.tipoDocumento()}" />
                        <p:ajax event="change" update=":userForm:ownerPanel" />
                    </p:selectOneRadio>

                    <div class="clear"/>

                    <p:outputLabel id="typeDocumentLabel" 
                                   value="#{managerImovel.proprietario.tipoDocumento}: " 
                                   styleClass="grid_3"/>

                    <f:validateBean disabled="true">
                        <p:inputMask id="typeDocumentInput" 
                                     value="#{managerImovel.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                              managerImovel.proprietario.cpf : managerImovel.proprietario.cnpj}"
                                     mask="#{managerImovel.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                             '999.999.999-99':'99.999.999/9999-99'}" 
                                     styleClass="grid_5" > 

                        </p:inputMask>
                    </f:validateBean>
                    <div class="clear"/>
                    <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                   rendered="#{managerImovel.proprietario.tipoDocumento.tipo eq 'CPF'}"/>
                    <p:inputText id="nomeInputText" styleClass="grid_19" 
                                 value="#{managerImovel.proprietario.nome}" 
                                 rendered="#{managerImovel.proprietario.tipoDocumento.tipo eq 'CPF'}" />

                    <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyInputText" 
                                   rendered="#{managerImovel.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />
                    <p:inputText id="nameFantasyInputText" styleClass="grid_19"
                                 value="#{managerImovel.proprietario.nomeFantasia}" 
                                 rendered="#{managerImovel.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />

                </p:panel>

                <h4 class="title">Endereço</h4>
                <p:panel id="addressPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">
                    <p:outputLabel value="CEP:" styleClass="grid_3" for="cepInputMask" />
                    <p:inputMask id="cepInputMask" styleClass="grid_4" mask="99.999-999"
                                 value="#{managerImovel.endereco.cep}" />
                    <div class="clear-both" />

                    <p:outputLabel value="Número:" styleClass="grid_3" for="numInputText" />
                    <p:inputText id="numInputText" styleClass="grid_2"
                                 value="#{managerImovel.endereco.numero}" />

                    <p:outputLabel value="Logradouro:" styleClass="grid_3 alpha" for="patioInputText" />
                    <p:inputText id="patioInputText" styleClass="grid_14"
                                 value="#{managerImovel.endereco.logradouro}" />

                    <div class="clear-both" />
                    <p:outputLabel value="Bairro:" styleClass="grid_3" for="neighborhoodInputText" />
                    <p:inputText id="neighborhoodInputText" styleClass="grid_19"
                                 value="#{managerImovel.endereco.bairro}" />

                </p:panel>


                <br/>
                <div class="buttonAction">
                     <p:commandButton  
                                title="Imprimir" 
                                ajax="false" update="@form" process="@this"
                                onclick="this.form.target='_blank'"
                                actionListener="#{managerImovel.relatorioRelacaoCadastral()}"
                                value="Imprimir"/>
<!--                    <p:commandButton id="bt_clear" value="Limpar" icon="ui-icon-close"
                                     actionListener="{managerImovel.clear()}"
                                     update="@form" />-->
                </div >
                <br/><br/>

<!--                <p:blockUI id="BLOCK" block="resultPanel" trigger="bt_add" > 
                    <p:graphicImage value="media/images/ajax-loader.gif"/>
                </p:blockUI> 
                <p:blockUI id="BLOCK_CLEAR" block="resultPanel" trigger="bt_clear" > 
                    <p:graphicImage value="media/images/ajax-loader.gif"/>
                </p:blockUI>

                <h4 class="title">Resultado</h4>
                <p:panel id="resultPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">

                    <p:dataTable id="tableImovel" var="item" value="{managerImovel.imoveis}" 
                                 styleClass="grid_24" rowIndexVar="rowid" 
                                 style="white-space: pre-wrap;"
                                 rowKey="{item.id}" rows="5" paginator="true"  
                                 paginatorPosition="bottom" emptyMessage="Nenhum registro">  
                        <f:facet name="header">
                            <p:outputLabel value="Imóvel {managerImovel.imoveis eq null ? '' : '('.concat(managerImovel.imoveis.size()).concat(')')}" />
                        </f:facet>
                        <p:column headerText="Ação" width="120">
                            <p:button title="Editar"
                                      href="editarimovel.xhtml?eImovel={item.id}"
                                      icon="ui-icon-pencil"/>
                            <p:button title="Visualizar"
                                      href="visualizarimovel.xhtml?vImovel={item.id}"
                                      icon="ui-icon-zoomin"/>
                            <p:commandButton title="Averbar" oncomplete="dlgAverbacao.show()"
                                             icon="ui-icon-clipboard">
                                <f:setPropertyActionListener target="{managerImovel.imovelAverbacao}" value="#{item}" />
                            </p:commandButton>

                            <p:commandButton update="@form" title="Excluir"
                                             oncomplete="dlg.show()" style="margin-left: -4px"
                                             icon="ui-icon-trash">
                                <f:setPropertyActionListener target="{managerImovel.imovelDelete}" value="{item}" />
                            </p:commandButton>

                            <p:dialog widgetVar="dlgAverbacao" modal="true" styleClass="dlgAverbacao" width="500" height="200" id="dlgAverbacao" header="Averbação">
                                <p:commandButton actionListener="{managerImovel.redirect('averbacaotransferencia.xhtml')}"
                                                 icon="ui-icon-transferthick-e-w"
                                                 value="Transferência"/>
                                <p:commandButton actionListener="{managerImovel.redirect('averbacaodesmembramento.xhtml')}"
                                                 icon="ui-icon-newwin"
                                                 disabled="true"
                                                 value="Desmembramento" />
                                <br/>
                                <p:commandButton actionListener="{managerImovel.redirect('averbacaomudancanome.xhtml')}"
                                                 icon="ui-icon-pencil"
                                                 value="Mudança de Nome" />
                                <p:commandButton actionListener="{managerImovel.redirect('averbacaotransferencia.xhtml')}"
                                                 icon="ui-icon-home"
                                                 disabled="true"
                                                 value="Mudança de Endereço" />
                                <br/>
                                <p:commandButton actionListener="{managerImovel.redirect('averbacaotransferencia.xhtml')}"
                                                 icon="ui-icon-document"
                                                 disabled="true"
                                                 value="Hipoteca" />
                                <p:commandButton actionListener="{managerImovel.redirect('averbacaotransferencia.xhtml')}"
                                                 icon="ui-icon-cancel"
                                                 disabled="true"
                                                 value="Calcelar Hipoteca"  />

                            </p:dialog>

                        </p:column>

                        <p:column headerText="Localização" width="250">  
                            <h:outputText value="Logradouro {item.enderecoImovel.logradouro}, Nº {item.enderecoImovel.numero}" />
                            <br/>
                        </p:column>
                        <p:column headerText="Bairro">  
                            <h:outputText value="{item.enderecoImovel.bairro}"/>
                        </p:column> 
                        <p:column headerText="Proprietário" width="450" style="white-space: pre-wrap;">  
                            <h:outputText style="{managerImovel.proprietartios(item) eq '' ? 'color: red;' : ''}"
                                          value="{managerImovel.proprietartios(item) eq '' ? 'Proprietário Pendente' : managerImovel.proprietartios(item)}"/>
                        </p:column> 
                    </p:dataTable> 

                </p:panel>-->


                <!--                    <div class="buttonAction">
                                        <p:button value="Voltar" href="indexrealty.xhtml"
                                                  icon="ui-icon-arrowreturnthick-1-w"/>
                
                                    </div>-->


<!--                <p:dialog id="modalDialog" header="Confirmação de remoção" widgetVar="dlg" modal="true" 
                          height="80" closable="true" resizable="false" >
                    <h:outputText value="Tem certeza que deseja remover este imóvel ?" />
                                        <h:outputText value="Permissão só ao administrador" />
                    <div class="buttonAction">
                                                <p:commandButton value="Sim"
                                                                 actionListener="{managerImovel.delete()}"
                                                                 update="@form"
                                                                 icon="ui-icon-check"/>
                                                <p:commandButton value="Não" icon="ui-icon-close"
                                                                 oncomplete="dlg.hide()" />

                        <h:outputText value="Exclusão só com autorização superior" />
                    </div>
                </p:dialog>

-->            </h:form>
        </ui:define>
    </ui:composition>
</html>
